package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_EVENT_HANDLE,desc = "事件处理")
public class DouLuoDaLuEventHandleCmd extends AbstractCommand {

    int action;
    int eventId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuEventHandleReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuEventHandleReqMsg.parseFrom(packet.getBytes());
        action = reqMsg.getAction();
        if(reqMsg.hasEventId()){
            eventId = reqMsg.getEventId();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        if ((ret = DouLuoDaLuMgr.activityInLieHunPeriod()) != 0) return;

        DouLuoDaLuProto.DouLuoDaLuEventHandleCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuEventHandleCrossReqMsg.newBuilder();
        crossReq.setAction(action);
        crossReq.setEventId(eventId);
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_EVENT_HANDLE, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_EVENT_HANDLE, DouLuoDaLuProto.DouLuoDaLuEventHandleRespMsg.newBuilder().setRet(ret));
        }
    }
}
